﻿
using System;
namespace YerongapillyGreens.Web.Extensions
{
    public static class StringExtensions
    {
        public static bool textEquals(this string str1, string str2)
        {
            return str1.ToLower() == str2.ToLower();
        }

        public static bool containsString(this string str1, string str2)
        {
            return str1.ToLower().Contains(str2.ToLower());
        }


        public static bool IsNull(this object obj)
        {
            return obj == null;
        }

        public static bool NotNull(this object obj)
        {
            return obj != null;
        }

        public static bool IsEmpty(this string text)
        {
            return string.IsNullOrEmpty(text);
        }

        public static bool NotEmpty(this string text)
        {
            return !string.IsNullOrEmpty(text);
        }

        public static int ToInt(this string str)
        {
            int result = 0;

            if (!string.IsNullOrEmpty(str))
                int.TryParse(str, out result);

            return result;
        }

        public static double ToDouble(this string str)
        {
            double result = 0;

            if (!string.IsNullOrEmpty(str))
                double.TryParse(str, out result);

            return result;
        }

        public static DateTime? ToDate(this string str)
        {
            DateTime result = DateTime.MinValue;

            if (!string.IsNullOrEmpty(str))
                DateTime.TryParse(str, out result);

            if (result == DateTime.MinValue)
                return null;
            else
                return result;
        }

        public static bool ToBool(this string str)
        {
            if (str.IsEmpty()) return false;

            if (str == "1" || str.ToLower() == "y" || str.ToLower() == "yes" || str.ToLower() == "true")
                return true;
            else
                return false;
        }
    }
}